package com.binance.notification.web.service.abnormaltrade.convert;

import java.util.List;
import java.util.Map;

import com.binance.master.utils.JsonUtils;
import com.binance.notification.data.models.AbnormalTradeNoticeLogModel;
import com.binance.notification.web.service.abnormaltrade.enums.AbnromalTradeBusinessTypeEnum;
import com.binance.notification.web.service.abnormaltrade.enums.AbnromalTradeNoticeDescEnum;
import com.binance.notification.web.service.abnormaltrade.models.AbnormalTradeNoticeLogBo;
import com.google.common.collect.Lists;

/**
 * AbnormalTradeNoticeLog Bo和Do的转换器
 */
public class AbnormalTradeNoticeLogConvertor {

    /**
     * 转换成数据层对象
     */
    public static AbnormalTradeNoticeLogModel toDo(AbnormalTradeNoticeLogBo abnormalTradeNoticeLogBo) {
        AbnormalTradeNoticeLogModel abnormalTradeNoticeLogModel = new AbnormalTradeNoticeLogModel();
        abnormalTradeNoticeLogModel.setId(abnormalTradeNoticeLogBo.getId());
        abnormalTradeNoticeLogModel.setSymbol(abnormalTradeNoticeLogBo.getSymbol());
        abnormalTradeNoticeLogModel.setQuoteAssetName(abnormalTradeNoticeLogBo.getQuoteAssetName());
        abnormalTradeNoticeLogModel.setDescCode(abnormalTradeNoticeLogBo.getDescCode().getDescCode());
        abnormalTradeNoticeLogModel.setBusinessType(abnormalTradeNoticeLogBo.getBusinessType().name());
        abnormalTradeNoticeLogModel
                .setBusinessData(JsonUtils.toJsonNotNullKey(abnormalTradeNoticeLogBo.getBusinessData()));
        abnormalTradeNoticeLogModel.setCreatedTime(abnormalTradeNoticeLogBo.getCreatedTime());
        abnormalTradeNoticeLogModel.setUpdateTime(abnormalTradeNoticeLogBo.getUpdateTime());
        return abnormalTradeNoticeLogModel;
    }

    /**
     * 转换成业务层对象
     */
    @SuppressWarnings("unchecked")
    public static AbnormalTradeNoticeLogBo toBo(AbnormalTradeNoticeLogModel abnormalTradeNoticeLogModel) {
        AbnormalTradeNoticeLogBo abnormalTradeNoticeLogBo = new AbnormalTradeNoticeLogBo();
        abnormalTradeNoticeLogBo.setId(abnormalTradeNoticeLogModel.getId());
        abnormalTradeNoticeLogBo.setSymbol(abnormalTradeNoticeLogModel.getSymbol());
        abnormalTradeNoticeLogBo.setQuoteAssetName(abnormalTradeNoticeLogModel.getQuoteAssetName());
        abnormalTradeNoticeLogBo.setDescCode(AbnromalTradeNoticeDescEnum.forDescCodeAndBusinessType(
                abnormalTradeNoticeLogModel.getDescCode(), abnormalTradeNoticeLogModel.getBusinessType()));
        abnormalTradeNoticeLogBo
                .setBusinessType(AbnromalTradeBusinessTypeEnum.valueOf(abnormalTradeNoticeLogModel.getBusinessType()));
        abnormalTradeNoticeLogBo
                .setBusinessData(JsonUtils.toObj(abnormalTradeNoticeLogModel.getBusinessData(), Map.class));
        abnormalTradeNoticeLogBo.setCreatedTime(abnormalTradeNoticeLogModel.getCreatedTime());
        abnormalTradeNoticeLogBo.setUpdateTime(abnormalTradeNoticeLogModel.getUpdateTime());
        return abnormalTradeNoticeLogBo;
    }

    /**
     * 转换成业务层对象
     */
    public static List<AbnormalTradeNoticeLogBo> toBoList(
            List<AbnormalTradeNoticeLogModel> abnormalTradeNoticeLogModels) {
        List<AbnormalTradeNoticeLogBo> abnormalTradeNoticeLogBoList = Lists.newArrayList();
        for (AbnormalTradeNoticeLogModel abnormalTradeNoticeLogModel : abnormalTradeNoticeLogModels) {
            AbnormalTradeNoticeLogBo abnormalTradeNoticeLogBo = toBo(abnormalTradeNoticeLogModel);
            abnormalTradeNoticeLogBoList.add(abnormalTradeNoticeLogBo);
        }
        return abnormalTradeNoticeLogBoList;
    }

}
